package com.atguigu.classroom.activity.controller;


import com.atguigu.classroom.activity.service.CouponInfoService;
import com.atguigu.classroom.model.activity.CouponInfo;
import com.atguigu.classroom.result.Result;
import com.atguigu.classroom.vo.activity.CouponInfoVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 优惠券信息 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2022-07-17
 */
@Api(tags = "新优惠卷接口")
@RestController
@RequestMapping("/admin/activity/couponInfo")
public class CouponInfoController {
    @Autowired
    private CouponInfoService couponInfoService;
    @ApiOperation("根据id获取优惠卷")
    @GetMapping("get/{id}")
    public Result getById(@PathVariable Long id){
        CouponInfo couponInfo = couponInfoService.getById(id);
        return Result.ok(couponInfo);
    }
    @ApiOperation("新增优惠卷")
    @PostMapping("save")
    public Result save(@RequestBody CouponInfo couponInfo){
        couponInfoService.save(couponInfo);
        return Result.ok(null);
    }
    @ApiOperation("根据id修改优惠卷")
    @PutMapping("update")
    public Result updateById(@RequestBody CouponInfo couponInfo){
        couponInfoService.updateById(couponInfo);
        return Result.ok(null);
    }
    @ApiOperation("删除优惠卷")
    @DeleteMapping("remove/{id}")
    public Result removeById(@PathVariable Long id){
        couponInfoService.removeById(id);
        return Result.ok(null);
    }
    @ApiOperation("批量删除优惠卷")
    @DeleteMapping("batchRemove")
    public Result removeByIds(@RequestBody List<Long> ids){
        couponInfoService.removeByIds(ids);
        return Result.ok(null);
    }
    @ApiOperation("获取优惠卷分页数据")
    @GetMapping("{page}/{limit}")
    public Result index(@PathVariable int page,
                        @PathVariable int limit){
        Page<CouponInfo> couponInfoPage=couponInfoService.getPage(page,limit);
        return Result.ok(couponInfoPage);
    }
}

